package com.csx.governance.traffic.condition.support;

import com.csx.governance.traffic.condition.Component;
import com.csx.governance.traffic.condition.ExpressionComponent;
import com.csx.governance.traffic.condition.constant.CompareOperator;
import com.csx.governance.traffic.condition.constant.ExpressionComponentType;

import java.util.Arrays;
import java.util.List;

/**
 * @author cuisongxu
 * @date 2023/2/25 17:32
 */
public class CompareExpressionComponent extends ExpressionComponent {

    public CompareExpressionComponent(String paramKey, CompareOperator operator, String paramValue) {
        super(paramKey, operator, paramValue);
    }

    public static class Builder extends ExpressionComponent.Builder {

        @Override
        public List<String> supportedConfigIds() {
            String prefix = ExpressionComponentType.EXP.name() + ".";
            return Arrays.asList(
                    prefix + CompareOperator.EQ.name(),
                    prefix + CompareOperator.NE.name(),
                    prefix + CompareOperator.GT.name(),
                    prefix + CompareOperator.LT.name(),
                    prefix + CompareOperator.GE.name(),
                    prefix + CompareOperator.LE.name(),
                    prefix + CompareOperator.INCLUDE.name(),
                    prefix + CompareOperator.EXCLUDE.name()
            );
        }

        @Override
        protected Component doBuild(String paramKey, CompareOperator operator, String paramValue) {
            return new CompareExpressionComponent(paramKey,operator, paramValue);
        }
    }
}
